package cn.djb.day28;

import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.List;

/**
 * @author DingJinBin
 * @description
 * @date 2022/4/29
 */
public class Main {

    public Number sum(Object... numbers) {
        BigDecimal sum = BigDecimal.ZERO;
        for (Object number : numbers) {
            if (null == number) continue;
            if (number instanceof CharSequence
                    || number instanceof Character) {
                //含有字母的排除
                String str = number.toString();
                if (str.matches(".*([A-Z]|[a-z])+.*")) {
                    continue;
                }
                BigDecimal decimal = new BigDecimal(str);
                sum = sum.add(decimal);
            } else if (number instanceof Boolean) {
                sum = sum.add(new BigDecimal((Boolean) number ? 1 : -1));
            } else {
                sum = sum.add(new BigDecimal(String.valueOf(number)));
            }
        }


        return sum;
    }

    public static void main(String[] args) {
        Main main = new Main();
        System.out.println(main.sum(1, 2, 3, 4, 5));
        System.out.println(main.sum(5, null, -5));
        System.out.println(main.sum("1.0", false, 1, true, 1, 'A', 1, 'B', 1, 'C', 1, 'D', 1, 'E', 1, 'F', 1, 'G', 1));
        System.out.println(main.sum(0.1, 0.2));
    }

    public List<Integer> perfectNumber() {
        List<Integer> list = new ArrayList<>();

        for (int i = 2; i < 10000; i++) {
            int sum = 0;
            for (int j = 1; j < i; j++) {
                if (i % j == 0) {
                    sum += j;
                }
            }
            if (sum == i) {
                list.add(i);
            }
        }
        return list;
    }

}
